home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 1817 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  1.4 KB

  1. Path: news.IntNet.net!news
  2. From: vic@intnet.net (Vic Sperry)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Random numbers
  5. Date: Thu, 11 Jan 1996 15:51:57 GMT
  6. Organization: Intelligence Network Online, Inc.
  7. Message-ID: <4d3c5h$6mu@mercury.IntNet.net>
  8. References: <4cul2d$gi@news.ran.es>
  9. NNTP-Posting-Host: pm-clw-5-37.intnet.net
  10. X-Newsreader: Forte Free Agent 1.0.82
  11.  
  12. mper@ran.es wrote:
  13.  
  14. >How many "random" numbers can be created using the rand() function without repitition. 
  15. >I am using this routine for a physics projects which simulates alpha scattering (Rutherford
  16. >Scattering), and I do about 1 million iterations through the main loop, creating 1 million random numbers.
  17. >Obviously, if its just repeating the numbers, the whole point of the simulation is gone.
  18.  
  19. >Anyone who knows, please answer,
  20.  
  21. >TIA
  22. >Martin.
  23.  
  24. Obtaining the answer to this question is far more complicated than you might expect.
  25. Donald Knuth wrote an excellent chapter on random numbers in "The Art of Computer
  26. Programming, Volume 2 / Seminumerical Algorithms". All pseudo random number
  27. generators repeat eventually, but if your compiler vendor used solid theory in
  28. implementing rand(), it will have a "very large" period (certainly more than 1 million).
  29. If you must be 100% positive, you could read Knuth and implement your own version
  30. of rand(). 
  31.  
  32.  
  33.  
  34. Vic Sperry
  35. vic@intnet.net
  36. Ever had a time-shifted E-mail conversation
  37. with your spouse who's asleep in the next room?
  38.  
  39.